home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / video / thrust-s.53 / thrust-s / thrust / src / fast_gr.c next >
C/C++ Source or Header  |  1995-10-20  |  5KB  |  282 lines

  1.  
  2. /* Written by Peter Ekberg, peda@lysator.liu.se */
  3.  
  4. #include <string.h>
  5. #include <stdio.h>
  6. #include <vgagl.h>
  7. #include <vga.h>
  8. #include "thrust.h"
  9.  
  10. byte *bild;
  11.  
  12. byte fuelblink;
  13.  
  14. void
  15. putscr(x, y)
  16.      int x,y;
  17. {
  18.   byte *tmp;
  19.   byte *maxtmp;
  20.   int res;
  21.  
  22.   maxtmp=bild+((PBILDY-1)*PBILDX<<1);
  23.   tmp=bild+y*(PBILDX<<1)+x;
  24.  
  25.   for(res=0; res<PSCRX*PSCRY; res+=PSCRX) {
  26.     memcpy(graph_mem+res, tmp, PSCRX);
  27.     if(tmp>=maxtmp)
  28.       tmp=bild+x;
  29.     else
  30.       tmp+=PBILDX<<1;
  31.   }
  32. }
  33.  
  34. void
  35. savegraphics(x, y)
  36.      int x,y;
  37. {
  38.   byte *tmp;
  39.   byte *maxtmp;
  40.   int res;
  41.   FILE *f;
  42.  
  43.   maxtmp=bild+((PBILDY-1)*PBILDX<<1);
  44.   tmp=bild+y*(PBILDX<<1)+x;
  45.   
  46.   f=fopen("screendump.bin","wb");
  47.   for(res=0; res<PSCRX*PSCRY; res+=PSCRX) {
  48.     fwrite(tmp,1,PSCRX,f);
  49.     if(tmp>=maxtmp)
  50.       tmp=bild+x;
  51.     else
  52.       tmp+=PBILDX<<1;
  53.   }
  54.   fclose(f);
  55. }
  56.  
  57. void
  58. putblock(x, y, source)
  59.      int x,y;
  60.      byte *source;
  61. {
  62.   int i;
  63.   byte *dest1, *dest2;
  64.  
  65.   dest1=bild+((y<<3)*(PBILDX<<1))+(x<<3);
  66.   dest2=dest1+((x>=BBILDX)?-(PBILDX):(PBILDX));
  67.   
  68.   for(i=0; i<8; i++) {
  69.     memcpy(dest1, source, 8);
  70.     memcpy(dest2, source, 8);
  71.     source+=8;
  72.     dest1+=PBILDX<<1;
  73.     dest2+=PBILDX<<1;
  74.   }
  75. }
  76.  
  77. void
  78. drawfuel(fuel)
  79.      int fuel;
  80. {
  81. /*
  82.   byte *dest;
  83.   byte color;
  84.   int size,i;
  85.  
  86.   dest=graph_mem+195*320+249;
  87.   fuelblink=(fuelblink-1)&31;
  88.   size=(fuel+9)/10;
  89.   if(size>10 || fuelblink&16)
  90.     color=4;
  91.   else
  92.     color=0;
  93.  
  94.   for(i=0; i<4; i++) {
  95.     memset(dest,color,size);
  96.     memset(dest+size,0,70-size);
  97.     dest+=320;
  98.   }
  99. */
  100.   char str[16];
  101.   byte tmpcol, tmppap, tmpflg;
  102.   tmpcol=chcolor;
  103.   tmppap=chpaper;
  104.   tmpflg=chflag;
  105.   chpaper=0;
  106.   fuelblink=(fuelblink-1)&31;
  107.   if(((fuel+9)/10)>10 || fuelblink&16)
  108.     chcolor=4;
  109.   else
  110.     chcolor=0;
  111.   chflag=1;
  112.   sprintf(str, "%d  ", fuel);
  113.   printgs(249, 195, str);
  114.   chflag=tmpflg;
  115.   chpaper=tmppap;
  116.   chcolor=tmpcol;
  117. }
  118.  
  119. void
  120. drawship(bx, by, ship, storage)
  121.      word bx,by;
  122.      byte *ship, *storage;
  123. {
  124.   byte *maxtmp, *tmp, pix;
  125.   int i,j;
  126.  
  127.   maxtmp=bild+((PBILDY-1)*PBILDX<<1);
  128.   tmp=bild+by*(PBILDX<<1)+bx;
  129.   for(i=0; i<256; i+=16) {
  130.     memcpy(storage+i, tmp, 16);
  131.     for(j=0; j<16; j++) {
  132.       pix=*(ship++);
  133.       if(pix)
  134.     *(tmp+j)=pix;
  135.     }
  136.     if(tmp>=maxtmp)
  137.       tmp=bild+bx;
  138.     else
  139.       tmp+=PBILDX<<1;
  140.   }
  141. }
  142.  
  143. void
  144. undrawship(bx, by, storage)
  145.      word bx,by;
  146.      byte *storage;
  147. {
  148.   byte *maxtmp, *tmp;
  149.   int i;
  150.  
  151.   maxtmp=bild+((PBILDY-1)*PBILDX<<1);
  152.   tmp=bild+by*(PBILDX<<1)+bx;
  153.   for(i=0; i<256; i+=16) {
  154.     memcpy(tmp, storage+i, 16);
  155.     if(tmp>=maxtmp)
  156.       tmp=bild+bx;
  157.     else
  158.       tmp+=PBILDX<<1;
  159.   }    
  160. }
  161.  
  162. void
  163. drawsquare(bx, by, object, storage, deltax, deltay)
  164.      word bx,by;
  165.      byte *object, *storage, deltax, deltay;
  166. {
  167.   byte *maxtmp, *tmp, pix;
  168.   int i,j;
  169.   word deltaxy;
  170.  
  171.   deltaxy=(word)deltax*deltay;
  172.   maxtmp=bild+((PBILDY-1)*PBILDX<<1);
  173.   tmp=bild+by*(PBILDX<<1)+bx;
  174.   for(i=0; i<deltaxy; i+=(int)deltax) {
  175.     memcpy(storage+i, tmp, (int)deltax);
  176.     for(j=0; j<(int)deltax; j++) {
  177.       pix=*(object++);
  178.       if(pix)
  179.     *(tmp+j)=pix;
  180.     }
  181.     if(tmp>=maxtmp)
  182.       tmp=bild+bx;
  183.     else
  184.       tmp+=PBILDX<<1;
  185.   }
  186. }
  187.  
  188. void
  189. undrawsquare(bx, by, storage, deltax, deltay)
  190.      word bx,by;
  191.      byte *storage, deltax, deltay;
  192. {
  193.   byte *maxtmp, *tmp;
  194.   int i;
  195.   word deltaxy;
  196.  
  197.   deltaxy=(word)deltax*deltay;
  198.   maxtmp=bild+((PBILDY-1)*PBILDX<<1);
  199.   tmp=bild+by*(PBILDX<<1)+bx;
  200.   for(i=0; i<deltaxy; i+=(int)deltax) {
  201.     memcpy(tmp, storage+i, (int)deltax);
  202.     if(tmp>=maxtmp)
  203.       tmp=bild+bx;
  204.     else
  205.       tmp+=PBILDX<<1;
  206.   }
  207. }
  208.  
  209. word
  210. testcrash(object, storage, len, shield)
  211.      byte *object, *storage;
  212.      word len;
  213.      byte shield;
  214. {
  215.   word i;
  216.   byte res=0;
  217.  
  218.   for(i=0; i<len; i++) {
  219.     if(*(object++)) {
  220.       if(*storage>res && (!shield || (shield && *storage<224)))
  221.     res=*storage;
  222.     }
  223.     storage++;
  224.   }
  225.   return(((word)res)>>5);
  226. }
  227.  
  228. void
  229. fadepalette(first, last, RGBtable, fade, flag)
  230.      word first, last;
  231.      Palette *RGBtable;
  232.      word fade;
  233.      word flag;
  234. {
  235. /*
  236.   static Palette tmpRGBtable;
  237.   int entries,e,i;
  238.   byte *c;
  239.  
  240.   entries=(e=last-first+1)*3;
  241.   memcpy(&tmpRGBtable, RGBtable, sizeof(Palette));
  242.   c=(char *)&tmpRGBtable;
  243.   for(i=0; i<sizeof(Palette); i++)
  244.     *(c++)=((*c)*fade)>>8;
  245.   if(flag)
  246.     vga_waitretrace();
  247.   gl_setpalettecolors(first, e, &tmpRGBtable);
  248. */
  249.   static int tmpRGBtable[768];
  250.   int entries,i;
  251.   int *c;
  252.   byte *d;
  253.  
  254.   entries=last-first+1;
  255.   
  256.   c=(int *)&tmpRGBtable;
  257.   d=(byte *)RGBtable;
  258.   i=0;
  259.  
  260.   while(i<3*entries) {
  261.     *c = (*d * fade) >> 8;
  262.     if(++i<3*entries) {
  263.       c++;
  264.       d++;
  265.     }
  266.   }
  267.  
  268.   if(flag)
  269.     vga_waitretrace();
  270.   vga_setpalvec(first, entries, tmpRGBtable);
  271. }
  272.  
  273. void
  274. setmargin(color, flag)
  275.      byte color,flag;
  276. {
  277.   if(!flag)
  278.     vga_waitretrace();
  279.  
  280. /* The color isn't changed */
  281. }
  282.